package searchandsort;

public class SortArrayByParity905 {
    public int[] sortArrayByParity(int[] nums) {
        int begin = 0;
        for (int i = nums.length - 1; i >= 0; i--) {
            while (i > begin && nums[i] % 2 == 0) {
                int tmp = nums[i];
                nums[i] = nums[begin];
                nums[begin++] = tmp;
            }
        }
        return nums;
    }
}
